FROM alpine:3.12.1

# 修改源
RUN echo "https://mirrors.aliyun.com/alpine/v3.6/main/" > /etc/apk/repositories &&\
    echo "https://mirrors.aliyun.com/alpine/v3.6/community/" >> /etc/apk/repositories &&\
    mkdir /wwwroot && mkdir /run/nginx &&\
    mkdir /cache && chmod 777 /cache

# 安装软件
RUN apk update && \
    apk add --no-cache ca-certificates && \
    apk add --no-cache curl bash tree tzdata 
RUN apk add nginx  
RUN apk add php7-dev php7-ctype php7-curl php7-dom php7-fpm php7-iconv php7-gd \
            php7-json php7-mysqli php7-openssl php7-pdo php7-pdo_sqlite php7-session php7-tokenizer\
            php7-sqlite3 php7-xml php7-xmlreader php7-zlib php7-phar php7-posix php7-mbstring php7-simplexml \
            build-base &&\ 
    cp -rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN apk add --no-cache musl-dev

# 添加用户
RUN adduser -D -g 'www' www

# 添加本地文件
ADD enterpoint.sh /enterpoint.sh
ADD info.php /wwwroot/info.php
ADD nginx.conf /etc/nginx/nginx.conf
ADD php-fpm.conf /etc/php7/php-fpm.conf
ADD php.ini /etc/php7/php.ini
ADD render-templates.sh /render-templates.sh
ADD substitute-env-vars.sh /substitute-env-vars.sh
ADD www.conf.tmpl /etc/nginx/sites-templates/www.conf.tmpl


# 修改权限
RUN touch /var/log/cron.log
RUN chmod +x /enterpoint.sh && \
    chmod +x /render-templates.sh && \
    chmod +x /substitute-env-vars.sh

# 放置文件
ADD app.tar /wwwroot

# 添加环境变量
ENV WWWROOT /wwwroot
ENV SITE_DOMAIN quzizhu.com
ENV DB_HOST db_server
ENV DB_USERNAME jr1
ENV DB_PASSWORD JRyhdweb123

# 添加暴露的端口
EXPOSE 80

ENTRYPOINT [ "./enterpoint.sh" ]
